/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.menosehmais.persistence;

import br.com.caelum.vraptor.ioc.Component;
import br.com.menosehmais.framework.persistence.DaoJpa2;
import br.com.menosehmais.model.ContaDO;
import br.com.menosehmais.model.PortletDO;
import br.com.menosehmais.model.SnitchDO;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;

/**
 *
 * @author Junior JAFJ
 */
@Component
public class SnitchDAO extends DaoJpa2<SnitchDO> {
    public SnitchDAO(EntityManager em) {
        super(SnitchDO.class, em);
    }

    public SnitchDO selectSnitchAccount(PortletDO portletDO, ContaDO contaDO) {
        String jpql = "SELECT sn FROM SnitchDO sn WHERE sn.idPortlet = :idPortlet AND sn.account.id = :idConta";
        TypedQuery<SnitchDO> query = entityManager.createQuery(jpql, SnitchDO.class);
        query.setParameter("idPortlet", portletDO.getId());
        query.setParameter("idConta", contaDO.getId());
        SnitchDO snitchDO = query.getSingleResult();

        return snitchDO;
    }
}
